package 二叉树;
//https://leetcode-cn.com/problems/symmetric-tree/
public class _101_对称二叉树 {
    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode() {}
        TreeNode(int val) { this.val = val; }
        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }
    public boolean isSymmetric(TreeNode root) {
       return check(root,root);
    }

    private boolean check(TreeNode root, TreeNode root1) {
        //如果都不是空对称
        if (root == null && root1 == null) return true;
        //有一个是就不对称
        if (root == null || root1 == null) return false;
        //返回 TreeNode的值 ，然后在递归
        return root.val == root1.val && check(root.left,root1.right) && check(root.right,root1.left);
    }
}
